package com.wyk.session;

import com.wyk.handler.ParameterMappingTokenHandler;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;

/**
 * @ClassName: wykSqlsession
 * @Description: todo mapper代理类
 * @Author: 初久
 * @Date: 2022/7/13 13:49
 **/
public class wykSqlsession {

    private Executor executor = new wykExecutor();

    private wykConfiguration myConfiguration = new wykConfiguration();

    public <T> T query(String statement, ParameterMappingTokenHandler tokenHandler, Map<String, Object> paramValuesMap, Method method) {
        return executor.query(statement, tokenHandler, paramValuesMap, method);
    }

    public int update(String statement, ParameterMappingTokenHandler tokenHandler, Map<String, Object> paramValuesMap, Method method) {
        return executor.update(statement, tokenHandler, paramValuesMap, method);
    }

    @SuppressWarnings("unchecked")
    public <T> T getMapper(Class<T> clazz) {
        //动态代理调用
        return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz},
                new wykMapperProxy(myConfiguration, this));
    }

}
